const path = require('path');
const fs = require('fs');

fs.readFile(path.join(__dirname, "../", "data.json"), 'utf8', (err, content)=>{
    if (err) throw err;
    let bookArray = JSON.parse(content);
    let arr = [];
    bookArray.forEach((item)=>{
        let sqlStr = `insert into t_book (name, author, category, description) values('${item.name}', '${item.author}', '${item.category}', '${item.desc}');`
        arr.push(sqlStr);
    });
    fs.writeFile(path.join(__dirname, 'book.sql'), arr.join('\n'), 'utf8', (err)=>{
        if (err) throw err;
        console.log('写入完成!');
    });
});

